//
//  ScreeningView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/19.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "ScreeningView.h"
#import "YLJCollectionViewFlowLayout.h"
#import "ScreeningCollectionViewCell.h"
#import "ScreeningHeaderCollectionReusableView.h"

@interface ScreeningView ()<YLJCollectionViewFlowLayoutDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) GLGWView * rightPopView;
@property (nonatomic,strong)UICollectionView * screening_Collection;

@end

@implementation ScreeningView

-(id)initWithFrame:(CGRect)aFrame inSuperView:(UIView *)aSuperView{
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];//145
        //
        self.rightPopView = [[GLGWView alloc] initWithFrame:CGRectMake(KScreenWidth, 0, KScreenWidth - kWidthProportion_In_iPhoneTriploid(35), self.height) inSuperView:self];
        YLJCollectionViewFlowLayout *flow_Layout = [[YLJCollectionViewFlowLayout alloc] init];
        flow_Layout.delegate = self;
        self.screening_Collection  = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.rightPopView.width, self.rightPopView.height - kHeightProportion_In_iPhoneTriploid(44)) collectionViewLayout:flow_Layout];
        self.screening_Collection.dataSource = self;
        self.screening_Collection.delegate = self;
        self.screening_Collection.backgroundColor = [UIColor whiteColor];
        [self.screening_Collection registerClass:[ScreeningCollectionViewCell class] forCellWithReuseIdentifier:[ScreeningCollectionViewCell cellIdentifier]];
        //
        [self.screening_Collection registerClass:[ScreeningHeaderCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[ScreeningHeaderCollectionReusableView headerViewIdentifier]];
        [self.rightPopView addSubview:self.screening_Collection];
        //
        [UIView animateWithDuration:0.25 animations:^{
            self.rightPopView.x = kWidthProportion_In_iPhoneTriploid(35);
        }];
        //
        GLGWView * leftTagView = [[GLGWView alloc] initWithFrame:CGRectMake(0, 0, kWidthProportion_In_iPhoneTriploid(35), self.height) inSuperView:self];
        UITapGestureRecognizer * tap_Collection = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(collection_action:)];
        tap_Collection.numberOfTouchesRequired = 1;
        tap_Collection.numberOfTapsRequired = 1;
        [leftTagView addGestureRecognizer:tap_Collection];
        leftTagView.userInteractionEnabled = YES;
        //重置 确定
        NSArray * titArr = @[@"重置",@"确定"];
        for (int i=0; i<2; i++) {
            GLGWButton * actionBut = [[GLGWButton alloc] initWithFrame:CGRectMake(self.screening_Collection.width/2*i, kY_With_View(self.screening_Collection, 0), self.screening_Collection.width/2, kHeightProportion_In_iPhoneTriploid(44)) hTitle:titArr[i] titleLableFont:SYSTEMFONT(14) titleLableColor:kColor_Rule_Yellow theCornerRadius:0 theBorderWidth:1.0 theBorderColor:kColor_Rule_Yellow backgroundColr:[UIColor whiteColor] inSuperView:self.rightPopView];
            if (i==1) {
                [actionBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                actionBut.backgroundColor = kColor_Rule_Yellow;
            }
        }
        
    }
    return self;
}

-(void)collection_action:(UITapGestureRecognizer *)tag{
    [UIView animateWithDuration:0.25 animations:^{
        self.rightPopView.x = KScreenWidth;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
#pragma mark =================== UICollectionViewDelegate,UICollectionViewDataSource,YLJCollectionViewFlowLayoutDelegate ===================
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 6;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}

- (ZLLayoutType)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout *)collectionViewLayout typeOfLayout:(NSInteger)section{
    return ClosedLayout;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ScreeningCollectionViewCell * cell = [ScreeningCollectionViewCell cellWithCollectionView:collectionView forIndexPath:indexPath];
    return cell;
}

//如果是百分比布局必须实现该代理，设置每个item的百分比，如果没实现默认比例为1
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout percentOfRow:(NSIndexPath*)indexPath{
    return 1;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((collectionView.frame.size.width - kWidthProportion_In_iPhoneTriploid(40))/3, kHeightProportion_In_iPhoneTriploid(40));
}
- (NSInteger)collectionView:(UICollectionView * __nullable)collectionView layout:(YLJCollectionViewFlowLayout* __nullable)collectionViewLayout columnCountOfSection:(NSInteger)section{
    return 3;
}

//如果是绝对定位布局必须是否该代理，设置每个item的frame
- (CGRect)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout rectOfItem:(NSIndexPath*)indexPath{
    return CGRectZero;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout *)collectionViewLayout zIndexOfItem:(NSIndexPath*)indexPath{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return kWidthProportion_In_iPhoneTriploid(10);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return kHeightProportion_In_iPhoneTriploid(10);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(kHeightProportion_In_iPhoneTriploid(10), kWidthProportion_In_iPhoneTriploid(10), 0, kWidthProportion_In_iPhoneTriploid(10));//top, left, bottom, right;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        ScreeningHeaderCollectionReusableView * hederTopView = [ScreeningHeaderCollectionReusableView headerViewWithCollectionView:collectionView forIndexPath:indexPath];
        return hederTopView;
    }
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(collectionView.frame.size.width, kHeightProportion_In_iPhoneTriploid(32));
}

-(void)dissmiss{
    [self removeFromSuperview];
}
                      
@end
